import puzautils.twitter_api.friend_exist as fe
import puzautils.table.puza_stream_table as pst
import puzautils.table.puza_row as pr
import time

A = pst.PuzaStreamTable()
A.Read('filter/target_tweets_retweet_naive_none.db')
output_f = open('./friends','w')
N = 0
M = 0
while True:
    raw_obj = A.StreamInRow()
    if raw_obj != None:
        r = pr.PuzaRow.Load(raw_obj)
        id1 = r['user_id']
        id2 = r['previous_user_id']
        result = fe.test_friendship(id1, id2)
        print id1, id2, result
        output_f.write(str(id1) + '\t' + str(id2) + '\t' + str(result) + '\n')
        if result == 1:
            N = N + 1
        elif result == 0:
            M = M + 1
        time.sleep(5)
    else:
        break
print N
print M
output_f.close()
